home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Universität Tübingen - 1997/1998 Winter
/
Universität Tübingen - Wintersemester 1997-98 - Uni-Informationssystem und Stadt-Informationssystem.iso
/
knl
/
search.pl
< prev
next >
Wrap
Perl Script
|
1997-08-14
|
4KB
|
161 lines
#!/bin/perl
# SEARCH.PL This Perl-script is called from the HTML-form
# "SEARCH_CC.HTML", and is intended to look up certain patterns in the
# file specified in "/info/www/data/uni/knl/txt/[name].txt", where [name] is
# the name of the input-form-field.
# Only plain characters and numbers are allowed (line 86).
#
# ThH, July-97
# Ver 1.2
#
###############################################################################
# Return html-header
###############################################################################
#
sub htmlheader {
print STDOUT <<EOD;
Content-type: text/html
<html>
<head>
<title>Search - Results</title>
</head>
<body>
<pre>
EOD
}
###############################################################################
# Message for invalid input:
###############################################################################
sub wrong_input {
print STDOUT <<EOD;
<BODY>
<STRONG>
Your request could not be handled, since it contains non-valid characters.
Please
<A HREF="http://www.uni-tuebingen.de/volab/search_cc.html">try again</A>
, using only the characters A-Z, a-z, 0-9, and "-".
</STRONG>
</BODY>
</HTML>
EOD
}
###############################################################################
#
# main program
#
################################################################################
sub main {
# location of the file with the information:
&htmlheader; # Header for Output
$error = 0;
# $error == 0 keine Sonderzeichen
# $error == 1 Sonderzeichen
$input = "";
# ------------------------------------------------------------
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$input,$ENV{"CONTENT_LENGTH"});
}
else {
# when called with PUT:
$input=$ENV{"QUERY_STRING"};
};
# $input hat jetzt den String des Formulars -> decodieren,
# syntaktisch testen und abspeichern
# ------------------------------------------------------------
$idx=0;
foreach $paar(split(/&/,$input)) {
($name,$value)=split(/=/,$paar);
$value=~ tr/+/ /;
$name=~ tr/+/ /;
$value =~ s/%(..)/pack("c",hex($1))/ge;
# $value auf spezielle Shell-Zeichen testen
# $value auf nonprintable ASCII < 32(dezimal) testen
# ------------------------------------------------------------
if ( ($value =~ /[;><&\*`\|\\]/) ||
($value =~ /[\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]/ )
)
{
# print ("+++ACHTUNG: $value \n");
$error = 1;
goto CONTINUE; # ungueltiges Zeichen, weitere Werte nicht pruefen;
# Sprung zu Label CONTINUE
};
$var_form[$idx] = $name;
$val_form[$idx] = $value;
$idx++;
}
# Sprung hierher im Fehlerfall oder sequentiell bei Nichtfehlerfall
# ------------------------------------------------------------
CONTINUE:
# $error == 1 ist Fehlerfall ungueltiges Zeichen
# ------------------------------------------------------------
if ($error == 1) {
# Reply to user:
&wrong_input;
}
else { # $error == 0;
# everything ok -> find information, and return it
}
# --------------------------------------------
for ($idx2 = 0; $idx2 < $idx; $idx2++) {
# Pass the values on the the folling search-routine:
$_ = $val_form[$idx2];
# Open the file with the information:
# --------------------------------------------
$infile = "/info/www/data/uni/knl/txt/$var_form[$idx2].txt";
open(IN_FILE, "<$infile");
print STDOUT "<h1>$var_form[$idx2] - Results</h1>\n";
print STDOUT "<p>The Following information has been found to match <I>$_</I>:</p>\n";
print STDOUT "<hr>\n";
$search = $_;
$line = "\n-----------------------\n";
while(<IN_FILE>) {
if (/_EOI_/) {
if (grep /$search/, @info) {
for ($i=0; $i<$index; $i++) {
$return_info[$ret_index++] = $info[$i];
}
$return_info[$ret_index++] = $line;
}
undef @info;
undef $index;
}
else {
$info[$index++] = $_;
}
}
# Finish everything off properly.
# --------------------------------------------
print STDOUT @return_info;
close IN_FILE;
} # for ($idx2 ...
exit 0
} # main {
#*****************************************************************
&main;
#*****************************************************************